package com.rajaev.dtu.tractor.domain.repository.mysql;

import com.rajaev.dtu.tractor.domain.entity.UserRolePo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserRoleDao {

    @Insert({"<script>",
            "insert into t_user_role (user_id,role_id)",
            "values ",
            "<foreach item='roleId'  collection='roleIds' separator=',' index = 'key'>",
            "(#{userId},#{roleId})",
            "</foreach>",
            "</script>"
    })
    void insert(@Param("roleIds") List<Integer> roleIds,@Param("userId") Integer userId);

    @Select({
            "<script>",
            "select id ,role_id roleId,user_id userId from t_user_role where user_id = #{userId}",
            "</script>"
    })
    UserRolePo selectUserRole(@Param("userId") Integer userId);

    @Delete({
            "delete from t_user_role where user_id = #{userId}",
    })
    void deleteUserRoles(Integer userId);


    @Delete({
            "delete from t_user_role where role_id = #{roleId}",
    })
    void deleteUserRolesByRoleId(Integer roleId);

}
